
# making an ebook from a latex file 
# http://hutchinson.belmont.ma.us/tth/ebooklatex.html

#.SUFFIXES: .o .c .tex .txt
.phony=dependencies

target=chekhov_xetex.pdf
#target=chekhov_e63.ps chekhov_a4.ps
#pdf=chekhov_e63.pdf chekhov_a4.pdf
# test.ps #Moroz.ps

#TEXFILES:=processed/bet1.tex processed/bet2.tex processed/chemist.tex processed/matveich.tex processed/muerte.tex

# search in chekhov.tex any lines that mention the processed folder, unless those who start with a comment  (%)
TEXFILES:=$(shell grep '\\input{processed' chekhov.tex | grep -v '^%' |sed 's?.*processed/\(.*\)}?processed/\1.tex?g')

#processed/princess.tex 

all: ps pdf

pdf: chekhov_xetex.pdf 

ps:  chekhov_a4.ps

ebook: chekhov_ebook.pdf


loop: 
	while sleep 10 ; do make ps ; done

Moroz.ps: Moroz_utf8.tex Makefile
	latex Moroz_utf8.tex
	dvips Moroz_utf8.dvi

test.ps: test.tex Makefile
	latex test.tex
	dvips test.dvi

edit:
	juffed Makefile chekhov_xetex.tex chekhov.tex&
	
	

#####################################################

# gets files in both russian and english and puts them in 2 columns, aligned like bilingual text books. Depends on commands_xetex.tex or commands_latex.tex depending on what you'll use to compile
processed/%.tex: Makefile mix.p txt/%.es.txt txt/%.ru.txt 
	./mix.p txt/$* > $@

dependencies: 	${TEXFILES}

%.dvi: Makefile %.tex chekhov.tex commands.tex commands_latex.tex  dependencies
	$(MAKE) dependencies
	-rm *.toc
	latex $*.tex
	latex $*.tex #twice, so we get the table of contents right
	 
%.ps: Makefile %.dvi 
	dvips $*.dvi
	 
#%.pdf: Makefile %.ps 
#	ps2pdf $*.ps

%.pdf: %.tex chekhov.tex commands.tex commands_xetex.tex dependencies
	xelatex $*.tex	
#####################################################

chekhov_a4.html: chekhov_a4.tex
	#tth -w2 -e2 chekhov_a4.tex -> need to replace charset with UTF8
	
	
clean:
	@rm -f *.log *.ps *.pdf *.dvi *.aux *.toc *.out
	@rm processed/*.tex
